﻿using System.Collections.Generic;

namespace xu.TinyDBConfigProvider
{
    internal static class CommonTool
    {
        public static IDictionary<string, string> Clone(this IDictionary<string, string> dict)
        {
            IDictionary<string, string> newDict = new Dictionary<string, string>();

            foreach (KeyValuePair<string, string> kv in dict) { newDict[kv.Key] = kv.Value; }

            return newDict;
        }

        public static bool IsChanged(IDictionary<string, string> oldDict, IDictionary<string, string> newDict)
        {
            if (oldDict.Count != newDict.Count) { return true; }

            foreach (var oldKV in oldDict)
            {
                string oldKey = oldKV.Key;
                string oldValue = oldKV.Value;
                string newValue = newDict[oldKey];
                if (oldValue != newValue) { return true; }
            }

            return false;
        }
    }
}